home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 25 / CU Amiga Magazine's Super CD-ROM 25 (1998)(EMAP Images)(GB)(Track 1 of 2)[!][issue 1998-08].iso / CUCD / Sound / MPEGAlib / developer / include / libraries / mpega.h
C/C++ Source or Header  |  1998-03-24  |  5KB  |  162 lines

  1. /*------------------------------------------------------------------------------
  2.  
  3.     File    :   MPEGA.h
  4.  
  5.     Author  :   Stéphane TAVENARD
  6.  
  7.     $VER:   MPEGA.h  1.0  (25/10/1997)
  8.  
  9.     (C) Copyright 1997-1997 Stéphane TAVENARD
  10.         All Rights Reserved
  11.  
  12.     #Rev|   Date   |                      Comment
  13.     ----|----------|--------------------------------------------------------
  14.     0   |25/10/1997| Initial revision                                     ST
  15.  
  16.     ------------------------------------------------------------------------
  17.  
  18.     MPEGA decoder library definitions
  19.  
  20. ------------------------------------------------------------------------------*/
  21.  
  22. #ifndef LIBRARIES_MPEGA_H
  23. #define LIBRARIES_MPEGA_H
  24.  
  25. #ifndef EXEC_TYPES_H
  26. #include <exec/types.h>
  27. #endif
  28.  
  29. #ifndef UTILITY_HOOKS_H
  30. #include <utility/hooks.h>
  31. #endif
  32.  
  33. /* Controls for decoding */
  34.  
  35. /* Qualities */
  36. #define MPEGA_QUALITY_LOW    0
  37. #define MPEGA_QUALITY_MEDIUM 1
  38. #define MPEGA_QUALITY_HIGH   2
  39.  
  40. /*
  41.    Bitstream Hook function is called like (SAS/C syntax):
  42.  
  43.  
  44.    ULONG __saveds __asm HookFunc( register __a0 struct Hook  *hook,
  45.                                   register __a2 APTR          handle,
  46.                                   register __a1 MPEGA_ACCESS *access );
  47.  
  48.    MPEGA_ACCESS struct specify bitstream access function & parameters
  49.  
  50.    access->func == MPEGA_BSFUNC_OPEN
  51.       open the bitstream
  52.       access->data.open.buffer_size is the i/o block size your read function can use
  53.       access->data.open.stream_size is the total size of the current stream
  54.                                     (in bytes, set it to 0 if unknown)
  55.       return your file handle (or NULL if failed)
  56.    access->func == MPEGA_BSFUNC_CLOSE
  57.       close the bitstream
  58.       return 0 if ok
  59.    access->func == MPEGA_BSFUNC_READ
  60.       read bytes from bitstream.
  61.       access->data.read.buffer is the destination buffer.
  62.       access->data.read.num_bytes is the number of bytes requested for read.
  63.       return # of bytes read or 0 if EOF.
  64.    access->func == MPEGA_BSFUNC_SEEK
  65.       seek into the bitstream
  66.       access->data.seek.abs_byte_seek_pos is the absolute byte position to reach.
  67.       return 0 if ok
  68. */
  69.  
  70. #define MPEGA_BSFUNC_OPEN  0
  71. #define MPEGA_BSFUNC_CLOSE 1
  72. #define MPEGA_BSFUNC_READ  2
  73. #define MPEGA_BSFUNC_SEEK  3
  74.  
  75. typedef struct {
  76.  
  77.    LONG  func;           /* MPEGA_BSFUNC_xxx */
  78.    union {
  79.       struct {
  80.          char *stream_name; /* in */
  81.          LONG buffer_size;  /* in */
  82.          LONG stream_size;  /* out */
  83.       } open;
  84.       struct {
  85.          void *buffer;      /* in/out */
  86.          LONG num_bytes;    /* in */
  87.       } read;
  88.       struct {
  89.          LONG abs_byte_seek_pos; /* out */
  90.       } seek;
  91.    } data;
  92.  
  93. } MPEGA_ACCESS;
  94.  
  95. /* Decoding output settings */
  96.  
  97. typedef struct {
  98.    WORD freq_div;    /* 1, 2 or 4 */
  99.    WORD quality;     /* 0 (low) .. 2 (high) */
  100.    LONG freq_max;    /* for automatic freq_div (if mono_freq_div == 0) */
  101. } MPEGA_OUTPUT;
  102.  
  103. /* Decoding layer settings */
  104. typedef struct {
  105.    WORD force_mono;        /* 1 to decode stereo stream in mono, 0 otherwise */
  106.    MPEGA_OUTPUT mono;      /* mono settings */
  107.    MPEGA_OUTPUT stereo;    /* stereo settings */
  108. } MPEGA_LAYER;
  109.  
  110. /* Full control structure of MPEG Audio decoding */
  111. typedef struct {
  112.    struct Hook *bs_access;    /* NULL for default access (file I/O) or give your own bitstream access */
  113.    MPEGA_LAYER layer_1_2;     /* Layer I & II settings */
  114.    MPEGA_LAYER layer_3;       /* Layer III settings */
  115.    WORD check_mpeg;           /* 1 to check for mpeg audio validity at start of stream, 0 otherwise */
  116.    LONG stream_buffer_size;   /* size of bitstream buffer in bytes (0 -> default size) */
  117.                               /* NOTE: stream_buffer_size must be multiple of 4 bytes */
  118. } MPEGA_CTRL;
  119.  
  120. /* MPEG Audio modes */
  121.  
  122. #define MPEGA_MODE_STEREO   0
  123. #define MPEGA_MODE_J_STEREO 1
  124. #define MPEGA_MODE_DUAL     2
  125. #define MPEGA_MODE_MONO     3
  126.  
  127. typedef struct {
  128.    /* Public data (read only) */
  129.    /* Stream info */
  130.    WORD  norm;          /* 1 or 2 */
  131.    WORD  layer;         /* 1..3 */
  132.    WORD  mode;          /* 0..3  (MPEGA_MODE_xxx) */
  133.    WORD  bitrate;       /* in kbps */
  134.    LONG  frequency;     /* in Hz */
  135.    WORD  channels;      /* 1 or 2 */
  136.    ULONG ms_duration;   /* stream duration in ms */
  137.    WORD  private_bit;   /* 0 or 1 */
  138.    WORD  copyright;     /* 0 or 1 */
  139.    WORD  original;      /* 0 or 1 */
  140.    /* Decoding info according to MPEG control */
  141.    WORD  dec_channels;  /* decoded channels 1 or 2 */
  142.    WORD  dec_quality;   /* decoding quality 0..2 */
  143.    LONG  dec_frequency; /* decoding frequency in Hz */
  144.  
  145.    /* Private data */
  146.    void  *handle;
  147. } MPEGA_STREAM;
  148.  
  149. #define MPEGA_MAX_CHANNELS 2    // Max channels
  150. #define MPEGA_PCM_SIZE     1152 // Max samples per frame
  151.  
  152. /* Error codes */
  153.  
  154. #define MPEGA_ERR_NONE     0
  155. #define MPEGA_ERR_BASE     0
  156. #define MPEGA_ERR_EOF      (MPEGA_ERR_BASE-1)
  157. #define MPEGA_ERR_BADFRAME (MPEGA_ERR_BASE-2)
  158. #define MPEGA_ERR_MEM      (MPEGA_ERR_BASE-3)
  159. #define MPEGA_ERR_NO_SYNC  (MPEGA_ERR_BASE-4)
  160.  
  161. #endif /* LIBRARIES_MPEGA_H */
  162.